﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HB.HttpServer;
using Sample.Model;

namespace Sample.Server.Controller
{
    [HttpPOST]
    [HttpRouter("/api/[controller]/[action]")]
    public class BooksController : ApiController, IBook
    {
        Random R = new Random();
        [HttpGET]
        public Task<List<Book>> GetList(int count)
        {
            List<Book> books = new List<Book>();
            for (int i = 0; i < count; i++)
            {

                books.Add(new Book() { AuthorName = $"haibao{i}", Name = "hhhhh", PublishYear = 2022 });
                R.NextBytes(books[i].Data1);
                R.NextBytes(books[i].Data2);
                R.NextBytes(books[i].Data3);
            }
            return Task.FromResult(books);
        }
        [HttpGET]
        public List<Book> GetList2()
        {
            List<Book> books = new List<Book>();
            for (int i = 0; i < 1000; i++)
            {
                books.Add(new Book() { AuthorName = $"haibao{i}", Name = "hhhhh", PublishYear = 2022 });
            }
            return books;
        }
        [HttpGET]
        [HttpRouter("/api/[controller]/Sum2")]
        public int Sum(int i, int j)
        {
            return i + j;
        }
        public Task<bool> IsBook(Book b)
        {
            return Task.FromResult(true);
        }
        public Task<int> GetCount()
        {
            return Task.FromResult(100);
        }
    }
}
